<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * @ApiTitle    (首页)
     * @ApiSummary  (首页)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/index/index)
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1578463253",
        "data": {
            "banner": [//轮播图
                {
                    "id": 2,//id
                    "image": "http://mite.w.brotop.cn/uploads/20200107/5ec13062630d25da83a305f5657822ee.png",//图片路径
                    "sort": 0
                },
                {
                    "id": 1,
                    "image": "http://mite.w.brotop.cn/uploads/20200107/5ec13062630d25da83a305f5657822ee.png",
                    "sort": 0
                }
            ],
            "thumbnail": {//缩略图
                "introduce": "http://mite.w.brotop.cn/uploads/20200107/e0bf0b8d402b5447575389b8bd57c225.png",//公司简介缩略图
                "service": "http://mite.w.brotop.cn/uploads/20200107/b48a6582d12da1fdafce424afbb3384d.png",//服务介绍缩略图
                "experience": "http://mite.w.brotop.cn/uploads/20200107/95539a1899f02bda4fe1920597affe37.png",//服务体验缩略图
                "register": "http://mite.w.brotop.cn/uploads/20200107/18e49cc54b697d369a143c9f1f369ac0.png"//会员注册缩略图
                "center": "http://mite.w.brotop.cn/uploads/20200107/18e49cc54b697d369a143c9f1f369ac0.png"//个人中心缩略图
                "reserve": "http://mite.w.brotop.cn/uploads/20200107/18e49cc54b697d369a143c9f1f369ac0.png"//一键预约缩略图
            }
        }
    })
     */
    public function index(){
        if($this->request->isGet()){
            $arr = [];
            //轮播图
            $banner = Common::selectData('banner','id,image,sort','sort desc,id desc');
            foreach ($banner as &$b_value){
                $b_value['image'] = Common::absolutionUrlOne($b_value['image']);
            }
            $arr['banner'] = $banner;
            //缩略图
            $introduce = Common::findWhereData('platform',['id'=>1],'id,thumbnail');//公司简介
            $service = Common::findWhereData('platform',['id'=>2],'id,thumbnail');//服务介绍
            $experience = Common::findWhereData('platform',['id'=>3],'id,thumbnail');//服务体验
            $register = Common::findWhereData('platform',['id'=>4],'id,thumbnail');//会员注册
            $center = Common::findWhereData('platform',['id'=>5],'id,thumbnail');//个人中心
            $reserve = Common::findWhereData('platform',['id'=>6],'id,thumbnail');//一键预约
            $arr['thumbnail']['introduce'] = Common::absolutionUrlOne($introduce['thumbnail']);
            $arr['thumbnail']['service'] = Common::absolutionUrlOne($service['thumbnail']);
            $arr['thumbnail']['experience'] = Common::absolutionUrlOne($experience['thumbnail']);
            $arr['thumbnail']['register'] = Common::absolutionUrlOne($register['thumbnail']);
            $arr['thumbnail']['center'] = Common::absolutionUrlOne($center['thumbnail']);
            $arr['thumbnail']['reserve'] = Common::absolutionUrlOne($reserve['thumbnail']);
            $this->success('成功',$arr);
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
     * @ApiTitle    (公司简介详情)
     * @ApiSummary  (公司简介详情)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/index/introduceDetail)
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1578463676",
        "data": {
            "id": 1,//详情id
            "image": "http://mite.w.brotop.cn/uploads/20200107/5ec13062630d25da83a305f5657822ee.png",//图片
            "content": "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Lorem ipsum dolor sit amet, consectetu s"//内容（富文本）
        }
    })
     */
    public function introduceDetail(){
        if($this->request->isGet()){
            $res = Common::findWhereData('platform',['id'=>1],'id,image,content');
            $res['image'] = Common::absolutionUrlOne($res['image']);
            $this->success('成功',$res);
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
     * @ApiTitle    (服务介绍详情)
     * @ApiSummary  (服务介绍详情)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/index/serviceDetail)
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1578463676",
        "data": {
            "id": 2,//详情id
            "image": "http://mite.w.brotop.cn/uploads/20200107/5ec13062630d25da83a305f5657822ee.png",//图片
            "content": "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Lorem ipsum dolor sit amet, consectetu s"//内容（富文本）
        }
    })
     */
    public function serviceDetail(){
        if($this->request->isGet()){
            $res = Common::findWhereData('platform',['id'=>2],'id,image,content');
            $res['image'] = Common::absolutionUrlOne($res['image']);
            $this->success('成功',$res);
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
     * @ApiTitle    (服务体验详情)
     * @ApiSummary  (服务体验详情)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/index/experienceDetail)
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1578463676",
        "data": {
            "id": 3,//详情id
            "content": "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Lorem ipsum dolor sit amet, consectetu s"//内容
        }
    })
     */
    public function experienceDetail(){
        if($this->request->isGet()){
            $res = Common::findWhereData('platform',['id'=>3],'id,content');
            $content = explode(',',$res['content']);
            foreach($content as $key => $c){
                $content[$key] = cdnurl($c,true);
            }
            $res['content'] = $content;
            $this->success('成功',$res);
        }else{
            $this->error('请求方式错误');
        }
    }
}
